﻿using Core.Service;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Text;

namespace BaiduApi
{
    public class Ocr : BaseService
    {
        public readonly Oauth Oauth;

        public Ocr(Oauth Oauth)
        {
            this.Oauth = Oauth;
        }

        public string GeneralBasic(Image Image)
        {
            using (MemoryStream Ms = new MemoryStream())
            {
                Image.Save(Ms, ImageFormat.Png);

                var Bytes = Ms.GetBuffer();
                
                var Base64Image = Convert.ToBase64String(Bytes);

                Console.WriteLine(Base64Image);

                var ResultText = PostRequest("https://aip.baidubce.com/rest/2.0/ocr/v1/general_basic?access_token= " + Oauth.AccessToken, "image=" + Base64Image, "application/x-www-form-urlencoded");

                return ResultText;
            }
        }
    }
}